/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:
 * Date: 2024-09-07
 * Time: 16:59
 */
public class Test {
    public static int binarySearch(int[] arr,int k){
        int left = 0;
        int right = arr.length - 1;


        while(right >= left){
            int mid = (left + right) / 2;
            if(arr[mid] < k){
                 left = mid + 1;
            } else if(arr[mid] > k){
                right = mid -1;
            }else {
                return mid;
}
        }
                return -1;
                }

public static void main(String[] args) {

        int[] arr = {0,1,2,3,4,5,6, 7 ,8,9,10};
    System.out.println(binarySearch(arr, 2));
    }
}
